package com.gdepri.cabelwellserver.client;


import java.io.*;
import java.net.Socket;
import java.util.Arrays;
import java.util.Scanner;

public class Client {

    public static void main(String[] args) throws IOException {

        //1.创建Socket对象，并同时请求与服务器程序的连接
        Socket socket = new Socket("121.36.223.253",18889);

//        InputStream inputStream = socket.getInputStream();
//        DataInputStream dataInputStream = new DataInputStream(inputStream);
//        System.out.println("打印所有的字节1");
//        //byte b = dataInputStream.readAllBytes();
//        System.out.println("打印所有的字节2");
//        System.out.println(b);

        //2.从Socket管道中得到一个字节输出流
        OutputStream os = socket.getOutputStream();
        //3.把低级的字节输出流构造成高级的数据输出流
        DataOutputStream dos = new DataOutputStream(os);
        //4.开始写数据
        Scanner sc = new Scanner(System.in);
        while(true){
            System.out.println("请输入消息：");
            String next = sc.nextLine();
            if("exit".equals(next)){
                dos.close();
                socket.close();
                break;
            }
            dos.writeUTF(next);
            dos.flush();
        }

    }
}
